Ccay.Module.define("Ccay.example.ui.igird.managerFunction", function (page, $S) {
	page.ready = function(){
		var linkBtns = [
			{text: "${id}", click: page.operateTest}
		];
		var gridOption = {
			minHeight: 400,
			maxHeight: 400,
			editMode: true,
			wrapHead: false,
			remoteSort: true,
			showStatus: true,
			customSetting: true,
			moveByKeyword: true,
			allowCopy: true,
			//dragObj: "row",
			toolPanel: "#tbriStudent",
			fullPanel: "#fsiStudent",
			fullOutTip: true,
			profileOpen:true,
			profileSelectPanel:"#aaa",
		    columns: [
		    	{columnType: 'select'},
		    	{columnType: 'operate', width: 70, freezeable: true, btns:linkBtns},
		 		{field: 'name', width:90, header: "ccay.common.label.name", freezeable: true, rule: {required: true}},
		 		{field: 'sex', width:70, header: "sSex", type: 'bool', format: {isIcon: true},cssName:"center",editable:false,content:"${#Ccay.Format.boolRender('grdiStudent',sex)}"},
		 		{field: 'age', width:70, header: "sAge", type: 'integer', sort: "asc", hiddenable: false, rule: {range: [0, 80]}},
		 		{field: 'birthday', width:110, header: "sBirthday", type: 'date', hidden: true},
		 		{field: 'blog', width:200, header: "sBlog", showTip:true},
		 		{field: 'lastUpdateDate', width:130, header: "ccay.common.label.lastUpdatedDate", type: 'datetime', editable: false, content: "${#getLastTime(lastUpdateDate)}"}
		    ],
			ajax:{
			   	url: 'services/ccay/demo/student/list/page/${pageSize}/${curPage}/${orderBy}'
			},
		    operation: {
		    	search: {
		    		btn: '#btniStudentSearch',
					panel: '#fmiStudent'
		    	},
		    	del: {
		    		btn: '#btniStudentDel',
		    		undoBtn: '#btniStudentUndoDel'
		    	},
		    	insert: {
		    		btn: '#btniStudentAdd',
		    		copy: true,
		    		clear: ['id', 'name', 'lastUpdateDate'],
		    		defaultRow: {sex: 1, blog: 'http://'}
		    	},
		    	save: {
		    		btn: '#btniStudentSave',
		    		ajax: {
		    			url: "services/ccay/demo/student/batch"
		    		}
		    	}
		    }
		};
		
		$S("#grdiStudent").igrid(gridOption);
		
		var gridOption1 = {
			minHeight: 200,
			maxHeight: 500,
			editMode: true,
			remoteSort: true,
			showStatus: true,
			customSetting: true,
			rowRender: "rowSpan",
			rowRenderOp: {simpleSort: true, spareFields: ["sex", "birthday", "lastUpdateDate"], order: ["blog", "age"]},
			toolPanel: "#tbrRowSpan",
			fullPanel: "#fsRowSpan",
		    columns: [
		    	{columnType: 'select', multi:true},
		    	{columnType: 'operate', width: 70, freezeable: true, btns:linkBtns},
		 		{field: 'name', width:90, header: "ccay.common.label.name", freezeable: true, rule: {required: true}},
		 		{field: 'sex', width:70, header: "sSex", type: 'bool', format: {isIcon: true}},
		 		{field: 'age', width:70, header: "sAge", type: 'integer', rule: {range: [0, 80]}},
		 		{field: 'birthday', width:110, header: "sBirthday", type: 'date', hidden: true},
		 		{field: 'blog', width:200, header: "sBlog", showTip:true},
		 		{field: 'lastUpdateDate', width:130, header: "ccay.common.label.lastUpdatedDate", type: 'datetime', editable: false, content: "${#getLastTime(lastUpdateDate)}"}
		    ],
			ajax:{
			   	url: 'services/ccay/demo/student/list/page/${pageSize}/${curPage}/${orderBy}'
			},
		    operation: {
		    	search: {
		    		btn: '#btnRowSpanSearch',
					panel: '#fmRowSpan'
		    	},
		    	del: {
		    		btn: '#btnRowSpanDel',
		    		undoBtn: '#btnRowSpanUndoDel'
		    	},
		    	insert: {
		    		btn: '#btnRowSpanAdd',
		    		copy: true,
		    		clear: ['id', 'name', 'lastUpdateDate'],
		    		defaultRow: {sex: 1, blog: 'http://'}
		    	},
		    	save: {
		    		btn: '#btnRowSpanSave',
		    		ajax: {
		    			url: "services/ccay/demo/student/batch"
		    		}
		    	}
		    }
		};
		
		var gridOption2 = {
			minHeight: 200,
			maxHeight: 500,
			editMode: true,
			remoteSort: true,
			showStatus: true,
			customSetting: true,
			rowRender: "group",
			rowRenderOp: {/*simpleSort: true,*/ spareFields: ["sex", "birthday", "lastUpdateDate"]},
			toolPanel: "#tbrGroup",
			fullPanel: "#fsGroup",
		    columns: [
		    	{columnType: 'select', multi:true},
		    	{columnType: 'operate', inner: true, width: 70, freezeable: true, btns:linkBtns},
		 		{field: 'name', width:90, header: "ccay.common.label.name", freezeable: true, rule: {required: true}},
		 		{field: 'sex', width:70, header: "sSex", type: 'bool', format: {isIcon: true}},
		 		{field: 'age', width:70, header: "sAge", type: 'integer', rule: {range: [0, 80]}},
		 		{field: 'birthday', width:110, header: "sBirthday", type: 'date', hidden: true},
		 		{field: 'blog', width:200, header: "sBlog", showTip:true, group: true},
		 		{field: 'lastUpdateDate', width:130, header: "ccay.common.label.lastUpdatedDate", type: 'datetime', editable: false, content: "${#getLastTime(lastUpdateDate)}"}
		    ],
			ajax:{
			   	url: 'services/ccay/demo/student/list/page/${pageSize}/${curPage}/${orderBy}'
			},
		    operation: {
		    	search: {
		    		btn: '#btnGroupSearch',
					panel: '#fmGroup'
		    	},
		    	del: {
		    		btn: '#btnGroupDel',
		    		undoBtn: '#btnGroupUndoDel'
		    	},
		    	insert: {
		    		btn: '#btnGroupAdd',
		    		copy: true,
		    		clear: ['id', 'name', 'lastUpdateDate'],
		    		defaultRow: {sex: 1, blog: 'http://'}
		    	},
		    	save: {
		    		btn: '#btnGroupSave',
		    		ajax: {
		    			url: "services/ccay/demo/student/batch"
		    		}
		    	}
		    }
		};
		
		var gridOption3 = {
			height: 300,
			editMode: true,
			lazyLoad: true,
			showStatus: true,
			customSetting: true,
			storageOp:{
				cache: true, // 是否缓存数据
				cacheKey: ["id"] // 缓存key
			},
			fullPanel: "#fsiStudent02",
	        columns: [
				 {columnType: "select", multi: true},
				 {field: 'id', width: 100, header: 'id', editable: false},
 			     {field: 'name', width:100, header: "name", rule: {required: true}},
 				 {field: 'description', width:200, header: "description"}
	        ],
		    ajax: {
		    	url: 'services/ccay/demo/grid/list/ranged/${start}/${end}/${orderBy}/${total}'
		    },
		    operation: {
		    	search: {
		    		btn: '#btniStudent02Search',
					panel: '#fmiStudent02'
		    	},
		    	del: {
		    		btn: '#btniStudent02Del',
		    		undoBtn: '#btniStudent02UndoDel'
		    	},
		    	insert: {
		    		btn: '#btniStudent02Add',
		    		copy: true,
		    		clear: ['id']
		    	},
		    	save: {
		    		btn: '#btniStudent02Save',
		    		ajax: {
		    			url: "services/ccay/demo/grid/batch"
		    		}
		    	}
		    }
	    };
	    
		$S("#otherFunctionDemo").ccayTab();
		
		//点击tab头后，才加载数据，只第一次生效
		$S("li[tabid='tab2']").one("click", function () {
			$S("#grdRowSpan").igrid(gridOption1);
		});
		$S("li[tabid='tab3']").one("click", function () {
			$S("#grdGroup").igrid(gridOption2);
		});
		$S("li[tabid='tab4']").one("click", function () {
			$S("#iStudent02").igrid(gridOption3);
		});
		
	};
	
	getLastTime = function(data){
		return Ccay.Format.toDateBefore(data && data.getUTCTime());
	};
	
	page.operateTest = function (value) {
		alert(Ccay.DataHelper.toJsonStr(value));
	};
	
	page.openDemo = function(tabId){
		$S("#managerFunctionDemo").getCcayTabManager().selectItem(tabId);
		$S("li[tabid='" + tabId + "']").click();
	};
});